using MicroMsg.Common.Event;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class ShareCardShow : Control
	{
		private const string TAG = "ShareCardShow";
		private EmojiText NickNameTxt;
		private DynamicTextBlock UserNameTxt;
		private Image HeadImg;
		private string cuUser;
		private ChatPeopleInfo mPeople;
		private EventWatcher mWatcherHeadImgAdd;
		private bool _contentLoaded;
		public ChatPeopleInfo People
		{
			get
			{
				return this.mPeople;
			}
			set
			{
				this.mPeople = value;
				this.RefreshPeople();
			}
		}
		public ShareCardShow()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.ShareCardShow_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.ShareCardShow_Unloaded));
		}
		protected virtual void InitDefaultStyleKey()
		{
		}
		protected virtual string getUserNameTxt()
		{
			if (!string.IsNullOrEmpty(this.People.Alias))
			{
				return string.Format(strings.FMsgWeiXinId, this.People.Alias);
			}
			return string.Format(strings.FMsgWeiXinId, this.People.UserName);
		}
		private void ShareCardShow_Unloaded(object sender, RoutedEventArgs e)
		{
			this.GetHeaderUnit();
		}
		private void ShareCardShow_Loaded(object sender, RoutedEventArgs e)
		{
			this.GetHeaderInit();
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.NickNameTxt = (base.GetTemplateChild("NickNameTxt") as EmojiText);
			this.UserNameTxt = (base.GetTemplateChild("UserNameTxt") as DynamicTextBlock);
			this.HeadImg = (base.GetTemplateChild("HeadImg") as Image);
			this.RefreshPeople();
		}
		private void RefreshPeople()
		{
			if (this.People == null)
			{
				return;
			}
			if (this.UserNameTxt == null)
			{
				return;
			}
			if (this.NickNameTxt == null)
			{
				return;
			}
			if (this.HeadImg == null)
			{
				return;
			}
			if (this.People.UserName != null)
			{
				this.UserNameTxt.Text = this.getUserNameTxt();
			}
			if (this.People.NickName != null)
			{
				this.NickNameTxt.Text = this.People.NickName;
			}
			this.cuUser = this.People.UserName;
			this.HeadImg.set_Source(HeadImgMgr.getHeadImage(this.mPeople.UserName, true));
		}
		private void GetHeaderInit()
		{
			this.mWatcherHeadImgAdd = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerHeadImgAdd));
			EventCenter.registerEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.mWatcherHeadImgAdd);
		}
		private void GetHeaderUnit()
		{
			EventCenter.removeEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.mWatcherHeadImgAdd);
		}
		private void onEventHandlerHeadImgAdd(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			List<string> listObject = evtArgs.getListObject<string>();
			if (listObject == null)
			{
				return;
			}
			if (string.IsNullOrEmpty(this.cuUser))
			{
				return;
			}
			using (List<string>.Enumerator enumerator = listObject.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					if (current != null && current.GetType() == typeof(string) && this.cuUser == current)
					{
						this.RefreshPeople();
						break;
					}
				}
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/Card/ShareCardShow.xaml", 2));
		}
	}
}
